﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Workflow.Common.FileUtil;
using Workflow.Resource;
using Workflow.Common;
using System.Configuration;
using System.IO;
public partial class ViewImg : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            System.Drawing.Image TheImg;
            int vPage = Convert.ToInt32(Request.QueryString["Pg"]) - 1;
            List<byte[]> msList = (List<byte[]>)this.Session["ShowTiff"];

            //if (ImpersonateLogon.impersonateValidUser(ConfigurationManager.AppSettings["ImpersonateUser"],
            //                         ConfigurationManager.AppSettings["ImpersonateDomain"],
            //                         ConfigurationManager.AppSettings["ImpersonatePassword"]))
            //{

                TheImg = new TIF(
                   Server.UrlDecode(Request.QueryString["FilePath"])).GetTiff_Merck(
                       System.Drawing.Image.FromStream(new MemoryStream (msList[vPage])),
                       System.Convert.ToInt16(Request.QueryString["Height"]),
                       System.Convert.ToInt16(Request.QueryString["Width"]));

   //             TheImg = new TIF(
   //Server.UrlDecode(Request.QueryString["FilePath"])).GetTiffImageThumb(
   //    System.Convert.ToInt16(Request.QueryString["Pg"]),
   //    System.Convert.ToInt16(Request.QueryString["Height"]),
   //    System.Convert.ToInt16(Request.QueryString["Width"]));



            //    ImpersonateLogon.undoImpersonation();
            //}
            //else
            //{
            //    throw new Exception("Impersonate Logon Error!");
            //}

            if (TheImg != null)
            {
                switch (Request.QueryString["Rotate"])
                {
                    case "90":
                        TheImg.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                        break;
                    case "180":
                        TheImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
                        break;
                    case "270":
                        TheImg.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipNone);
                        break;
                }

                Response.ContentType = "image/jpeg";
                TheImg.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                TheImg.Dispose();
            }

        }
        catch (Exception exception)
        {
            //Response.Write(Workflow.Resource.Global.Readimageerror);
            Response.Write(exception.Message);
        }
    }
}
